#pragma once
#include "CTimer.h"
#include "CJoystick.h"
namespace DarkStorm2D {
namespace SystemCore {
	using namespace DarkStorm2D::InputCore;

	class CEventQueue
	{
	protected:
		ALLEGRO_EVENT_QUEUE* m_EventQueue;
	public:
		enum eSourceEvent
		{
			SOURCE_EVENT_TIMER,
			SOURCE_EVENT_KEYBOARD,
			SOURCE_EVENT_MOUSE,
			SOURCE_EVENT_JOYSTICK,
			SOURCE_EVENT_DISPLAY,
		};
		CEventQueue()
		{
			m_EventQueue = al_create_event_queue();
		}

		~CEventQueue()
		{
			al_destroy_event_queue(m_EventQueue);
		}

		inline void Register(int SourceEvent, IEventReceiver* Reciver)
		{
			switch (SourceEvent)
			{
			case SOURCE_EVENT_TIMER:
				al_register_event_source(m_EventQueue,al_get_timer_event_source((dynamic_cast<CTimer *>(Reciver))->m_Timer));
				break;

			case SOURCE_EVENT_KEYBOARD:
				al_register_event_source(m_EventQueue,al_get_keyboard_event_source());
				break;

			case SOURCE_EVENT_MOUSE:
				al_register_event_source(m_EventQueue,al_get_mouse_event_source());
				break;

			case SOURCE_EVENT_JOYSTICK:
				al_register_event_source(m_EventQueue,al_get_joystick_event_source());
				break;

			case SOURCE_EVENT_DISPLAY:
				al_register_event_source(m_EventQueue,al_get_display_event_source(al_get_current_display()));
				break;
			}


		}

		inline bool IsEmpty() {return al_event_queue_is_empty(m_EventQueue);}
		inline void WaitForEvent(ALLEGRO_EVENT* ReturnEvent)
		{
			al_wait_for_event(m_EventQueue,ReturnEvent);
		}

		inline bool PeekNextEvent(ALLEGRO_EVENT* ReturnEvent)
		{
			return al_peek_next_event(m_EventQueue,ReturnEvent);
		}
		ALLEGRO_EVENT_QUEUE* GetQueue()
		{
			return m_EventQueue;
		}
	};
};
};

